package chapter23;

/**
 * @author lzy
 * @version v1.0
 * Create DateTime: 2019/2/27 14:34
 */
public class SimpleStaticProxyDemo {
    public static void main(String[] args) {
        IService realService = new RealService();
        IService traceService = new TraceProxy(realService);
        traceService.sayHello();
    }

    static interface IService {
        public void sayHello();
    }

    static class RealService implements IService {
        @Override
        public void sayHello() {
            System.out.println("hello");
        }
    }

    static class TraceProxy implements IService {
        private IService realService;

        public TraceProxy(IService realService) {
            this.realService = realService;
        }

        @Override
        public void sayHello() {
            System.out.println("entering sayHello");
            realService.sayHello();
            System.out.println("leaving sayHello");
        }
    }

}
